// pages/another/another.js
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'
import QQMapWX from '../../static/js/qqmap-wx-jssdk.min'

Page({
  /**
   * Page initial data
   */
  data: {
    detail: {},
    showBack: false
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    this.setData({
      detail: options
    })
  },

  back() {
    Dialog.confirm({
      title: '是否保存草稿？'
    })
      .then(() => {
        let pages = getCurrentPages()
        let prevPage = pages[pages.length - 3]
        prevPage.saveDraft()
        this.sendNotify()
      })
      .catch(() => {
        this.sendNotify()
      })
  },

  toHome() {
    wx.switchTab({
      url: '/pages/main/main'
    })
  },

  sendNotify() {
    // 发送微信订阅消息推送 审核通知
    const that = this
    wx.requestSubscribeMessage({
      tmplIds: [
        '-DHKrW9DRvbg3sEoVRYtcRxRyr-kYzyTN-9BNCY89rI',
        'b7FIjt52cUMvTClpMJKJLe8lzi4rnQsWlUc7D5VYGoA',
        'PbmE0p7hgtUXlZcUEgR_qBcP3tMhbe1-_wKNw7CkoZY'
      ],
      complete(res) {
        that.toHome()
      }
    })
  },

  onShareAppMessage: function () {
    this.setData({
      showBack: true
    })
    setTimeout(() => {
      wx.showToast({
        title: '分享成功！等待好友支付',
        icon: 'none',
        duration: 5000
      })
    }, 2000)
    return {
      title: '帮我付款' + this.data.detail.price + '元！',
      imageUrl: 'https://m.xianmaiyangsheng.com/xcxImg/image/daifu.png',
      path: `/pages/another-pay/another-pay?id=${this.data.detail.id}&key=${this.data.detail.key}`
    }
  }
})